﻿using System.Text.Json;
using System.Text.Json.Serialization;

namespace OrderingFoot.Core
{
    /// <summary>
    /// 字符串序列化
    /// </summary>
    public class StringNullConverter : JsonConverter<string>
    {
        /// <summary>
        /// reade
        /// </summary>
        public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            return reader.GetString();
        }

        /// <summary>
        /// write
        /// </summary>
        public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
        {
            var result = string.IsNullOrWhiteSpace(value) ? "" : value;
            writer.WriteStringValue(result);
        }
    }
}
